<%@ page language="java" contentType="text/html; charset=UTF-8"
         pageEncoding="UTF-8"%>
<%@ page import="java.sql.*;"%>
<%
    String path = request.getContextPath();
    String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<%@include file="header.jsp"%>
	<div class="container">
		<div class="stage">
			<h2 class="stage-heading">更新书籍</h2>
<%
	String num = request.getParameter("num");
	try {
		Class.forName("com.mysql.jdbc.Driver");
	} catch (ClassNotFoundException e) {
		out.print(e);
	}

	Connection con;
	Statement sql;
	ResultSet rs;

	String url = "jdbc:mysql://localhost:3306/bookinfo?useUnicode=true&amp;characterEncoding=UTF-8&amp;zeroDateTimeBehavior=convertToNull";
	String user = "root";
	String psword = "chuichuiqqt";

	try { 
		con=DriverManager.getConnection(url,user,psword);
        sql=con.createStatement();
	    rs = sql.executeQuery("select * from book where num='" + num + "'");
	    if ( rs.next() ) {
%>
	<form id="edit">	
		<input value="<%=rs.getString("num")%>" name="num" type="hidden"/>
		<div class="form-group">
			<input placeholder="书名" class="form-control" value="<%=rs.getString("name")%>" name="name" type="text"/>
		</div>
		<div class="form-group">
			<input placeholder="作者" class="form-control" value="<%=rs.getString("author")%>" name="author" type="text"/>
		</div>
		<div class="form-group">
			<input placeholder="出版社" class="form-control" value="<%=rs.getString("publisher")%>" name="publisher" type="text"/>
		</div>
		<div class="form-group">
			<input placeholder="版本" class="form-control" value="<%=rs.getString("revision")%>" name="revision" type="text"/>
		</div>
		<div class="form-group">
			<input placeholder="价格" class="form-control" value="<%=rs.getString("price")%>" name="price" type="text"/>
		</div>
		<div class="form-group">
			<input placeholder="出版时间" class="form-control" name="time" type="date"/>
		</div>
		<button id="edit-btn" data-src="book-edit-action.jsp" class="btn btn-lg btn-primary btn-block" type="submit">提交</button>
	</form>
	<script type="text/javascript">
		$(function() {
			$("#edit").submit(function(event) {
				event.preventDefault();
				var url = $("#edit-btn").attr("data-src");
				$.ajax({
					url:url,
					async:false,
					type:'post',
					data:$(this).serialize(),
					dataType:'html',
					context:$("#myModal"),
					success:function(data) {
						$(this).find(".modal-body").html(data);
						$(this).modal('toggle');
					}
				});
			}
		);
		});
	</script>	
<%
		}
	} catch (SQLException e) {
		out.print(e);
	}
%>
	</div>
	<div id="myModal" class="modal fade">
	  <div class="modal-dialog">
	    <div class="modal-content">
	      <div class="modal-header">
	        <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
	        <h4 class="modal-title">提示</h4>
	      </div>
	      <div class="modal-body">
	        <p>One fine body&hellip;</p>
	      </div>
	      <div class="modal-footer">
	        <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
	      </div>
	    </div><!-- /.modal-content -->
	  </div><!-- /.modal-dialog -->
	</div><!-- /.modal -->
</body>
</html>